import { BasicColumn, FormSchema } from '@/components/Table';
import { h, ref } from 'vue';
import { Tag } from 'ant-design-vue';
import { departmentTreeList } from '@/api/sys/msUser';
import { ywGroupSelectList } from '@/api/heng/ywManage';

import { useUserStore } from '@/store/modules/user';
const userStore = useUserStore();

//表格列名
export const columns: BasicColumn[] = [
  {
    title: '部门名称',
    dataIndex: 'deptName',
    width: 130,
  },
  {
    title: '客户类型',
    dataIndex: 'type',
    width: 100,
    customRender: ({ text }) => {
      let value = '';
      if (text === 1) {
        value = '新老客户';
      } else if (text === 2) {
        value = '固定客户';
      }
      return value;
    },
  },
  {
    title: '新客户首三单比例',
    dataIndex: 'newCustomerRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 100,
  },
  {
    title: '老客户订单类型',
    dataIndex: 'oldCustomerType',
    customRender: ({ text }) => {
      let value = '';
      if (text === 1) {
        value = '不分成品和配件';
      } else if (text === 2) {
        value = '区分成品和配件';
      } else if (text === 3) {
        value = '区分国内外销售';
      }
      return value;
    },
    width: 130,
  },
  {
    title: '老客户不分成品和配件抽成比例',
    dataIndex: 'oldCustomerOriginalRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 120,
  },

  {
    title: '老客户成品比例',
    dataIndex: 'oldCustomerFinishedRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 120,
  },
  {
    title: '老客户配件比例',
    dataIndex: 'oldCustomerPartRate',
    format: (value) => `${value ? value + '%' : ''}`,

    width: 120,
  },
  {
    title: '老客户国内销售比例',
    dataIndex: 'oldCustomerHomeRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 130,
  },
  {
    title: '老客户国外销售比例',
    dataIndex: 'oldCustomerForeignRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 130,
  },
  {
    title: '客户编号',
    dataIndex: 'fixedCustomerNo',
    width: 120,
  },
  {
    title: '客户固定比例',
    dataIndex: 'fixedCustomerRate',
    format: (value) => `${value ? value + '%' : ''}`,
    width: 100,
  },

  {
    title: '创建时间',
    width: 180,
    dataIndex: 'createTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '搜索',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'deptId',
    label: 'deptId',
    show: false,
  },
  {
    field: 'deptName',
    label: '部门名称',
    required: true,
    slot: 'deptName',
  },
  {
    field: 'type',
    label: '客户类型',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '老新客户', value: 1 },
        { label: '固定客户', value: 2 },
      ],
    },
  },
  {
    field: 'newCustomerRate',
    label: '新客户首三单比例',
    component: 'InputNumber',
    suffix: '%',
    componentProps: {
      min: 0,
      max: 100,
    },
    ifShow({ values }) {
      return values.type === 1;
    },
  },
  {
    field: 'oldCustomerType',
    label: '老客户订单类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '不分成品和配件', value: 1 },
        { label: '区分成品和配件', value: 2 },
        { label: '区分国内外销售', value: 3 },
      ],
    },
    ifShow({ values }) {
      return values.type === 1;
    },
  },

  {
    field: 'oldCustomerOriginalRate',
    label: '老客户不分成品和配件抽成比例',
    component: 'InputNumber',
    suffix: '%',
    componentProps: {
      min: 0,
      max: 100,
    },
    ifShow({ values }) {
      return values.oldCustomerType === 1;
    },
  },
  {
    field: 'oldCustomerFinishedRate',
    label: '老客户成品比例',
    component: 'InputNumber',
    suffix: '%',
    componentProps: {
      min: 0,
      max: 100,
    },
    ifShow({ values }) {
      return values.oldCustomerType === 2;
    },
  },
  {
    field: 'oldCustomerPartRate',
    label: '老客户配件比例',
    component: 'InputNumber',
    suffix: '%',
    componentProps: {
      min: 0,
      max: 100,
    },
    ifShow({ values }) {
      return values.oldCustomerType === 2;
    },
  },

  {
    field: 'oldCustomerHomeRate',
    label: '老客户国内销售比例',
    component: 'InputNumber',
    suffix: '%',
    componentProps: {
      min: 0,
      max: 100,
    },
    ifShow({ values }) {
      return values.oldCustomerType === 3;
    },
  },

  {
    field: 'oldCustomerForeignRate',
    label: '老客户国外销售比例',
    component: 'InputNumber',
    suffix: '%',
    componentProps: {
      min: 0,
      max: 100,
    },
    ifShow({ values }) {
      return values.oldCustomerType === 3;
    },
  },

  {
    field: 'fixedCustomerNo',
    label: '客户编号',
    slot: 'fixedCustomerNo',
    ifShow({ values }) {
      return values.type === 2;
    },
  },
  {
    field: 'fixedCustomerRate',
    label: '客户固定比例',
    component: 'InputNumber',
    suffix: '%',
    componentProps: {
      min: 0,
      max: 100,
    },
    ifShow({ values }) {
      return values.type === 2;
    },
  },
];
